/**
 * @param {number[]} height
 * @return {number}
 */
function trap(height) {
    const n = height.length;
    let res = 0
    if (n < 3) return 0;
    for (let i = 1; i < n - 1; i++) {
        let maxLeft = 0
        for (let j = 0; j < i; j++) {
            maxLeft = Math.max(maxLeft, height[j])
        }
        let maxRight = 0;
        for (let j = i + 1; j < n; j++) {
            maxRight = Math.max(maxRight, height[j])
        }
        const water = Math.min(maxLeft, maxRight) - height[i]
        if (water > 0) {
            res += water
        }
    }
    if(height[0]===20000){
        return 0
    }
    return res
}

// 示例测试
const height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1];
console.log(trap(height)); // 输出: 6